package org.farm2.tools.caches;

/**
 * 缓存key
 */
public enum FarmCacheKeys {

    LOGIN_USER("登录用户", 5000, NONE(), hour(3)),

    ONLINE_USER("在线用户", 5000, NONE(), minutes(30)),

    PARAMETER("系统参数", 5000, NONE(), hour(3)),

    SALT("加密盐", 5000, minutes(1), NONE()),

    LOGIN_ERROR_NUM("登录校验错误次数", 5000, NONE(), minutes(10)),

    LOGIN_IMG_CODES("缓存的登录验证码", 5000, NONE(), minutes(2)),

    JWT_REFRESH_KES("JWT刷新次数", 5000, NONE(), minutes(10)),

    CLIENT_VISIT_COUNTER("客户端访问计数器", 10000, minutes(1), NONE()),

    RESOURCE_FILE("附件信息", 3000, NONE(), hour(8)),

    EXTEND_FILE("扩展文件信息", 3000, NONE(), hour(8)),

    TALK_MSG("AI会话信息缓存", 3000, NONE(), hour(2)),

    PROCESS("处理进度", 1000, minutes(10), NONE()),
    ;

    private String title;
    private Integer maxNum;
    private Integer liveSeconds;
    private Integer idleSeconds;

    /**
     * @param title 缓存描述
     * @param maxNum 最大缓存条目
     * @param liveSeconds 根据存入时间过期（TTL）
     * @param idleSeconds 根据最后一次访问时间过期（TTI）
     */
    FarmCacheKeys(String title, int maxNum, int liveSeconds, int idleSeconds) {
        this.title = title;
        this.maxNum = maxNum;
        this.liveSeconds = liveSeconds;
        this.idleSeconds = idleSeconds;
    }

    private static int minutes(int minute) {
        return minute * 60;
    }

    private static int second(int second) {
        return second;
    }

    private static int hour(int hour) {
        return minutes(hour * 60);
    }

    private static int NONE() {
        return -1;
    }

    public Integer getIdleSeconds() {
        return idleSeconds;
    }

    public Integer getMaxNum() {
        return maxNum;
    }

    public Integer getLiveSeconds() {
        return liveSeconds;
    }

    public String getTitle() {
        return title;
    }
}
